﻿<!--*********************************************************************

   Extended WPF Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. The commercial version of Extended WPF Toolkit also includes
   priority technical support, commercial updates, and many additional 
   useful WPF controls if you license Xceed Business Suite for WPF.

   Visit http://xceed.com and follow @datagrid on Twitter.

  ********************************************************************-->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Twi.COMMON.WPF.CtlExtended"
                    xmlns:conv="clr-namespace:Twi.COMMON.WPF.CtlExtended.Core.Converters">

   <conv:ColorToSolidColorBrushConverter x:Key="ColorToSolidColorBrushConverter" />

   <LinearGradientBrush x:Key="ColorPickerDarkBorderBrush" EndPoint="0.5,1" StartPoint="0.5,0">
      <GradientStop Color="#FFA3AEB9" Offset="0" />
      <GradientStop Color="#FF8399A9" Offset="0.375" />
      <GradientStop Color="#FF718597" Offset="0.375" />
      <GradientStop Color="#FF617584" Offset="1" />
   </LinearGradientBrush>

   <LinearGradientBrush x:Key="ColorCanvasBackgroundBrush" StartPoint="0,0" EndPoint="0,1">
      <LinearGradientBrush.GradientStops>
         <GradientStopCollection>
            <GradientStop Offset="0" Color="#FFffffff" />
            <GradientStop Offset="1" Color="#FFE8EBED" />
         </GradientStopCollection>
      </LinearGradientBrush.GradientStops>
   </LinearGradientBrush>

   <DrawingBrush  x:Key="CheckerBrush" Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
      <DrawingBrush.Drawing>
         <DrawingGroup>
            <GeometryDrawing Brush="White">
               <GeometryDrawing.Geometry>
                  <RectangleGeometry Rect="0,0 100,100" />
               </GeometryDrawing.Geometry>
            </GeometryDrawing>
            <GeometryDrawing Brush="LightGray">
               <GeometryDrawing.Geometry>
                  <GeometryGroup>
                     <RectangleGeometry Rect="0,0 50,50" />
                     <RectangleGeometry Rect="50,50 50,50" />
                  </GeometryGroup>
               </GeometryDrawing.Geometry>
            </GeometryDrawing>
         </DrawingGroup>
      </DrawingBrush.Drawing>
   </DrawingBrush>

   <SolidColorBrush x:Key="HorizontalSliderTrackNormalBackground" Color="#FFE7EAEA" />

   <LinearGradientBrush x:Key="HorizontalSliderTrackNormalBorder" EndPoint="0,1" StartPoint="0,0">
      <GradientStop Color="#FFAEB1AF" Offset="0.1" />
      <GradientStop Color="White" Offset=".9" />
   </LinearGradientBrush>

   <LinearGradientBrush x:Key="ThumbStroke" EndPoint="0.5,1" StartPoint="0.5,0">
      <GradientStop Color="#FFA3AEB9" Offset="0" />
      <GradientStop Color="#FF8399A9" Offset="0.375" />
      <GradientStop Color="#FF718597" Offset="0.375" />
      <GradientStop Color="#FF617584" Offset="1" />
   </LinearGradientBrush>

   <LinearGradientBrush x:Key="ThumbFill" StartPoint="0,0" EndPoint="0,1">
      <LinearGradientBrush.GradientStops>
         <GradientStopCollection>
            <GradientStop Offset="0" Color="#FFfefefe" />
            <GradientStop Offset="0.5" Color="#FFeff1f2" />
            <GradientStop Offset="1" Color="#FFd0d6db" />
         </GradientStopCollection>
      </LinearGradientBrush.GradientStops>
   </LinearGradientBrush>

   <SolidColorBrush x:Key="ThumbMouseOver" Color="#FFE5F2F6" />

   <Style x:Key="ColorCanvasTextBoxStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
      <Setter Property="Background" Value="Transparent" />
      <Style.Triggers>
         <Trigger Property="IsFocused" Value="False">
            <Setter Property="BorderBrush" Value="Transparent" />
         </Trigger>
      </Style.Triggers>
   </Style>

   <Style x:Key="SliderRepeatButtonStyle"
         TargetType="{x:Type RepeatButton}">
      <Setter Property="OverridesDefaultStyle" Value="true" />
      <Setter Property="IsTabStop" Value="false" />
      <Setter Property="Focusable" Value="false" />
      <Setter Property="Background" Value="Transparent" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type RepeatButton}">
               <Border Background="{TemplateBinding Background}" />
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="CustomThumbForSlider" TargetType="{x:Type Thumb}">
      <Setter Property="OverridesDefaultStyle" Value="True" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
               <Rectangle x:Name="_thumb" Fill="{StaticResource ThumbFill}" Stroke="{StaticResource ThumbStroke}" Height="14" Width="8" RadiusX="1" RadiusY="1" />
               <ControlTemplate.Triggers>
                  <Trigger Property="IsMouseOver" Value="True">
                     <Setter TargetName="_thumb" Property="Rectangle.Fill" Value="{StaticResource ThumbMouseOver}" />
                  </Trigger>
               </ControlTemplate.Triggers>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="VerticalSlideThumbStyle" TargetType="{x:Type Thumb}">
      <Setter Property="Focusable" Value="false" />
      <Setter Property="OverridesDefaultStyle" Value="true" />
      <Setter Property="Height" Value="12" />
      <Setter Property="Width" Value="11" />
      <Setter Property="Foreground" Value="Gray" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
               <Canvas SnapsToDevicePixels="true">
                  <Path x:Name="LeftArrow" Stretch="Fill" StrokeLineJoin="Round" Stroke="#FF000000" Fill="#FF000000" Data="F1 M 276.761,316L 262.619,307.835L 262.619,324.165L 276.761,316 Z " RenderTransformOrigin="0.5,0.5" Width="6" Height="8">
                     <Path.RenderTransform>
                        <TransformGroup>
                           <ScaleTransform />
                           <SkewTransform />
                           <RotateTransform />
                           <TranslateTransform Y="6" X="-3" />
                        </TransformGroup>
                     </Path.RenderTransform>
                  </Path>
                  <Path x:Name="RightArrow" Stretch="Fill" StrokeLineJoin="Round" Stroke="#FF000000" Fill="#FF000000" Data="F1 M 276.761,316L 262.619,307.835L 262.619,324.165L 276.761,316 Z " RenderTransformOrigin="0.5,0.5" Width="6" Height="8">
                     <Path.RenderTransform>
                        <TransformGroup>
                           <ScaleTransform />
                           <SkewTransform />
                           <RotateTransform Angle="-180" />
                           <TranslateTransform Y="6" X="8" />
                        </TransformGroup>
                     </Path.RenderTransform>
                  </Path>
               </Canvas>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style x:Key="ColorCanvasSliderStyle" TargetType="{x:Type Slider}">
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type Slider}">
               <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                  <Grid>
                     <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" MinHeight="{TemplateBinding MinHeight}" />
                        <RowDefinition Height="Auto" />
                     </Grid.RowDefinitions>
                     <TickBar x:Name="TopTick" Fill="{TemplateBinding Foreground}" Height="4" Placement="Top" Grid.Row="0" Visibility="Collapsed" />
                     <TickBar x:Name="BottomTick" Fill="{TemplateBinding Foreground}" Height="4" Placement="Bottom" Grid.Row="2" Visibility="Collapsed" />
                     <Border x:Name="TrackBackground" BorderBrush="{StaticResource HorizontalSliderTrackNormalBorder}" BorderThickness="1" Background="{StaticResource HorizontalSliderTrackNormalBackground}" CornerRadius="1" Height="4.0" Margin="5,0" Grid.Row="1" VerticalAlignment="center">
                        <Canvas Margin="-6,-1">
                           <Rectangle x:Name="PART_SelectionRange" Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" Height="4.0" Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" StrokeThickness="1.0" Visibility="Hidden" />
                        </Canvas>
                     </Border>
                     <Track x:Name="PART_Track" Grid.Row="1">
                        <Track.DecreaseRepeatButton>
                           <RepeatButton Command="{x:Static Slider.DecreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                        </Track.DecreaseRepeatButton>
                        <Track.IncreaseRepeatButton>
                           <RepeatButton Command="{x:Static Slider.IncreaseLarge}" Style="{StaticResource SliderRepeatButtonStyle}" />
                        </Track.IncreaseRepeatButton>
                        <Track.Thumb>
                           <Thumb x:Name="Thumb" Style="{StaticResource CustomThumbForSlider}" />
                        </Track.Thumb>
                     </Track>
                  </Grid>
               </Border>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style TargetType="{x:Type local:ColorCanvas}">
      <Setter Property="Background" Value="{StaticResource ColorCanvasBackgroundBrush}" />
      <Setter Property="BorderBrush" Value="{StaticResource ColorPickerDarkBorderBrush}" />
      <Setter Property="BorderThickness" Value="1" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ColorCanvas}">
               <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Padding="3">
                  <Grid Margin="2">
                     <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                     </Grid.RowDefinitions>
                     <Grid>
                        <Grid.ColumnDefinitions >
                           <ColumnDefinition Width="200" />
                           <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                           <RowDefinition Height="Auto" />
                           <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Border BorderThickness="1" BorderBrush="DarkGray" ClipToBounds="True" Background="{StaticResource CheckerBrush}">
                           <Canvas x:Name="PART_ColorShadingCanvas" Width="200" Height="100" HorizontalAlignment="Left" VerticalAlignment="Top">
                              <Rectangle x:Name="ColorShadingRectangle"
                                         Height="{Binding ElementName=PART_ColorShadingCanvas, Path=Height}"
                                         Width="{Binding ElementName=PART_ColorShadingCanvas, Path=Width}"
                                         Fill="{Binding SelectedColor, ElementName=PART_SpectrumSlider, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                              <Rectangle x:Name="WhiteGradient" Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}" Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                 <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                                       <GradientStop Offset="0" Color="#ffffffff" />
                                       <GradientStop Offset="1" Color="Transparent" />
                                    </LinearGradientBrush>
                                 </Rectangle.Fill>
                              </Rectangle>
                              <Rectangle x:Name="BlackGradient" Width="{Binding ElementName=PART_ColorShadingCanvas,Path=Width}" Height="{Binding ElementName=PART_ColorShadingCanvas,Path=Height}">
                                 <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0,1" EndPoint="0, 0">
                                       <GradientStop Offset="0" Color="#ff000000" />
                                       <GradientStop Offset="1" Color="#00000000" />
                                    </LinearGradientBrush>
                                 </Rectangle.Fill>
                              </Rectangle>
                              <Canvas x:Name="PART_ColorShadeSelector" Width="10" Height="10" IsHitTestVisible="False">
                                 <Ellipse Width="10" Height="10" StrokeThickness="3" Stroke="#FFFFFFFF" IsHitTestVisible="False" />
                                 <Ellipse Width="10" Height="10" StrokeThickness="1" Stroke="#FF000000" IsHitTestVisible="False" />
                              </Canvas>
                           </Canvas>
                        </Border>

                        <Border Grid.Row="1" Margin="0,5,0,0">
                           <Grid>
                              <Grid.ColumnDefinitions>
                                 <ColumnDefinition Width="*" />
                                 <ColumnDefinition Width="*" />
                              </Grid.ColumnDefinitions>
                              <Border Background="{StaticResource CheckerBrush}" Height="22" Margin="2,0,2,0" BorderThickness="1" BorderBrush="#FFC9CACA">
                                 <Rectangle x:Name="SelectedColor" Fill="{Binding SelectedColor, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ColorToSolidColorBrushConverter}}" />
                              </Border>
                              <TextBox Grid.Column="1" Text="{Binding HexadecimalString, RelativeSource={RelativeSource TemplatedParent}}" Margin="2,0,2,0" VerticalAlignment="Center" Style="{StaticResource ColorCanvasTextBoxStyle}" />
                           </Grid>
                        </Border>

                        <Border Grid.Column="1" Grid.RowSpan="2" Margin="4,-8,0,0" ClipToBounds="False">
                           <local:ColorSpectrumSlider x:Name="PART_SpectrumSlider" VerticalAlignment="Stretch" />
                        </Border>
                     </Grid>

                     <Border MinWidth="180" Grid.Row="1" BorderThickness="1" ClipToBounds="True" Margin="0,10,0,0">
                        <Grid>
                           <Grid.RowDefinitions>
                              <RowDefinition Height="Auto" />
                              <RowDefinition Height="Auto" />
                              <RowDefinition Height="Auto" />
                              <RowDefinition Height="Auto" />
                           </Grid.RowDefinitions>
                           <Grid.ColumnDefinitions>
                              <ColumnDefinition Width="Auto" />
                              <ColumnDefinition Width="*" />
                              <ColumnDefinition Width="Auto" />
                           </Grid.ColumnDefinitions>

                           <TextBlock Grid.Row="0"
                                      Grid.Column="0"
                                      Text="R"
                                      VerticalAlignment="Center" />
                           <Slider x:Name="PART_RSlider"
                                   Maximum="255"
                                   TickFrequency="1"
                                   Grid.Row="0"
                                   Grid.Column="1"
                                   Margin="4,6,4,6"
                                   Style="{StaticResource ColorCanvasSliderStyle}"
                                   Value="{Binding R, RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Center" />
                           <TextBox Grid.Row="0"
                                    Grid.Column="2"
                                    Text="{Binding Value, ElementName=PART_RSlider}"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource ColorCanvasTextBoxStyle}" />

                           <TextBlock Grid.Row="1"
                                      Grid.Column="0"
                                      Text="G"
                                      VerticalAlignment="Center" />
                           <Slider x:Name="PART_GSlider"
                                   Maximum="255"
                                   TickFrequency="1"
                                   Grid.Row="1"
                                   Grid.Column="1"
                                   Margin="4,6,4,6"
                                   Style="{StaticResource ColorCanvasSliderStyle}"
                                   Value="{Binding G, RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Center" />
                           <TextBox Grid.Row="1"
                                    Grid.Column="2"
                                    Text="{Binding Value, ElementName=PART_GSlider}"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource ColorCanvasTextBoxStyle}" />

                           <TextBlock Grid.Row="2"
                                      Grid.Column="0"
                                      Text="B"
                                      VerticalAlignment="Center" />
                           <Slider x:Name="PART_BSlider"
                                   Maximum="255"
                                   TickFrequency="1"
                                   Grid.Row="2"
                                   Grid.Column="1"
                                   Margin="4,6,4,6"
                                   Style="{StaticResource ColorCanvasSliderStyle}"
                                   Value="{Binding B, RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Center" />
                           <TextBox Grid.Row="2"
                                    Grid.Column="3"
                                    Text="{Binding Value, ElementName=PART_BSlider}"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource ColorCanvasTextBoxStyle}" />

                           <TextBlock Grid.Row="3"
                                      Grid.Column="0"
                                      Text="A"
                                      VerticalAlignment="Center" />
                           <Slider x:Name="PART_OpacitySlider"
                                   Grid.Row="3"
                                   Grid.Column="1"
                                   Maximum="255"
                                   Margin="4,6,4,6"
                                   Style="{StaticResource ColorCanvasSliderStyle}"
                                   Value="{Binding Path=A, RelativeSource={RelativeSource TemplatedParent}}"
                                   VerticalAlignment="Center" />
                           <TextBox Grid.Row="3"
                                    Grid.Column="3"
                                    Text="{Binding Value, ElementName=PART_OpacitySlider}"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource ColorCanvasTextBoxStyle}" />
                        </Grid>
                     </Border>
                  </Grid>
               </Border>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

   <Style TargetType="{x:Type local:ColorSpectrumSlider}">
      <Setter Property="Orientation" Value="Vertical" />
      <Setter Property="Background" Value="Transparent" />
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
      <Setter Property="Minimum" Value="1" />
      <Setter Property="Maximum" Value="360" />
      <Setter Property="TickFrequency" Value="0.001" />
      <Setter Property="IsSnapToTickEnabled" Value="True" />
      <Setter Property="IsDirectionReversed" Value="False" />
      <Setter Property="IsMoveToPointEnabled" Value="True" />
      <Setter Property="Value" Value="0" />
      <Setter Property="Template">
         <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:ColorSpectrumSlider}">
               <Grid>
                  <Border x:Name="PART_TrackBackground" BorderBrush="DarkGray" BorderThickness="1" Width="15" Margin="0,8,0,0">
                     <Rectangle x:Name="PART_SpectrumDisplay" Stretch="Fill" VerticalAlignment="Stretch" />
                  </Border>

                  <Track Name="PART_Track">
                     <Track.DecreaseRepeatButton>
                        <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="Slider.DecreaseLarge" />
                     </Track.DecreaseRepeatButton>
                     <Track.IncreaseRepeatButton>
                        <RepeatButton Style="{StaticResource SliderRepeatButtonStyle}" Command="Slider.IncreaseLarge" />
                     </Track.IncreaseRepeatButton>
                     <Track.Thumb>
                        <Thumb Style="{StaticResource VerticalSlideThumbStyle}" />
                     </Track.Thumb>
                  </Track>
               </Grid>
            </ControlTemplate>
         </Setter.Value>
      </Setter>
   </Style>

</ResourceDictionary>